package com.bosssoft.boss_exam_web.Controller;

import com.bosssoft.boss_exam_core.util.web.ResponseUtil;
import com.bosssoft.boss_exam_core.validator.Order;
import com.bosssoft.boss_exam_core.validator.Sort;
import com.bosssoft.boss_exam_db.model.vo.ApplicantExamPaperVO;
import com.bosssoft.boss_exam_db.service.busines.ApplicantExamPaperService;
import com.bosssoft.boss_exam_db.service.busines.ExamExamPaperService;
import com.bosssoft.boss_exam_web.common.annotation.LoginAdmin;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@AllArgsConstructor
@NoArgsConstructor
@RequestMapping("/admin")
public class SelectCheckExamController {

//  引入考试-试卷服务
    @Autowired
    private ExamExamPaperService examExamPaperService;

//  引入应聘者-试卷服务
    @Autowired
    private ApplicantExamPaperService applicantExamPaperService;

    @ApiOperation(value="公司查询", notes="可根据考试批次查询所有未改试卷" ,httpMethod="GET",response = Object.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="examCode", value="考试批次号", dataType = "String", required=false, dataTypeClass=String.class),
            @ApiImplicitParam(name="page", value="当前页码", dataType = "String", required=false, dataTypeClass=Integer.class),
            @ApiImplicitParam(name="limit", value="每页显示条数", dataType = "String", required=false, dataTypeClass=Integer.class),
            @ApiImplicitParam(name="sort", value="排序依据", dataType = "String", required=false, dataTypeClass=String.class),
            @ApiImplicitParam(name="order", value="排序方式", dataType = "String", required=false, dataTypeClass=String.class)
    })
    @RequestMapping("/examExamPaper/fetchExamExamPaperList")
    public Object list(@LoginAdmin String adminId,
                       @RequestParam String examCode,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        if (adminId == null) {
            return ResponseUtil.unlogin();
        }
        List<ApplicantExamPaperVO> examExamPapers = applicantExamPaperService.queryByCondition(examCode);
        PageHelper.startPage(page, limit);
        PageInfo<ApplicantExamPaperVO> paperPageInfo = new PageInfo<ApplicantExamPaperVO>(examExamPapers);
        Map<String, Object> data = new HashMap<>();
        data.put("total", paperPageInfo.getTotal());
        data.put("items", paperPageInfo.getList());
        return ResponseUtil.ok(data);
    }

}
